
import React, { Component } from 'react';
import {
   AppRegistry,
  StyleSheet,
  Text,
  View,
  Slider,
  ViewPagerAndroid,Image,
  TouchableOpacity,
  Switch
} from 'react-native';
export default class CommonCell extends Component {
   render() {
    return (
      <TouchableOpacity onPress={()=>{alert('点击了'+this.props.title)}}>
      <View style={styles.container}>

        {/****左边****/}
        <Text style={{marginLeft:10}}>
         {this.props.title}
        </Text>
      {/****右边或者开关这个判断函数****/}
      {this.renderRightView()}
      {/****右边箭头****/}

      </View>
      </TouchableOpacity>
    );
  }
  renderRightView(){
    if (this.props.isSwitch) {//true,返回开关
        return(
          //这里的Switch组件点击不好使，回头看下第10次视频！！！
            <Switch
              value={false}
              onValueChange={()=>{()=>{alert('点击了'+this.props.title)}}}
              style={{marginRight:10}}
            />
          )
    }
    else{
        return(
          <View style={{flexDirection:'row', alignItems:'center'}}>
          {this.rightTitle()}

          <Image source={require('../../assets/home_arrow.png')}
          style={{width:8,height:13,marginRight:10}} />
          </View>
      )}
  }
  rightTitle(){
     if (this.props.rightTitle !== '') {
            return(
                <Text style={{color:'gray', marginRight:3, fontSize:12}}>{this.props.rightTitle}</Text>
              )
          }
  }
}

const styles = StyleSheet.create({
  container:{
    height:37,
    backgroundColor:'white',
    borderBottomColor:'#dddddd',
    borderBottomWidth:0.5,
    //主轴对齐方式
    flexDirection:'row',
    justifyContent:'space-between',
    //侧轴的对齐方式
    alignItems:'center'
  }
});

//输出组件类
module.exports =CommonCell;
